package com.agileboot.admin.config;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.mail.javamail.JavaMailSenderImpl;

@Configuration
public class MailConfig {

    @Value("${spring.mail.host: smtp.qq.com}")
    private String host;
    @Value("${spring.mail.port: 465}")
    private int port;
    @Value("${spring.mail.username: 2183517383@qq.com}")
    private String username;
    @Value("${spring.mail.password: wbrkaumtvudjebfa}")
    private String password;
    @Bean
    public JavaMailSender javaMailSender() {
        JavaMailSenderImpl mailSender = new JavaMailSenderImpl();
        mailSender.setHost(host);
        mailSender.setPort(port);
        mailSender.setUsername(username);
        mailSender.setPassword(password);
        mailSender.setDefaultEncoding("UTF-8"); // 设置默认编码
        mailSender.setProtocol("smtps"); // 设置协议为SMTPS（SMTP over SSL/TLS）
        return mailSender;
    }
}
